<?php

//require_once("../bd/DataBase.php");
/* require_once("../fachadasBD/MinieventoMapper.php"); */
/* require_once("../fachadasBD/MinigrupoMapper.php"); */
/* require_once("../fachadasBD/MininoticiasMapper.php"); */
/* require_once("../fachadasBD/MiniperfilMapper.php"); */
/* require_once("../mappers/MiniEvento.php"); */
/* require_once("../mappers/MiniGrupo.php"); */
/* require_once("../mappers/MiniNoticias.php"); */
/* require_once("../mappers/MiniPerfil.php"); */
require_once("../fachadas/fachadaBuscar.php");
require_once("../vistas/vistaBuscar.php");

//$_GET['search']="a";
//$_GET['type']="perfil";

if (isset($_GET['type']) || (isset($_SESSION["searchType"]) && strcmp($_SESSION["searchType"], "normal") != 0)){
  if (isset($_GET['type']))
    $_SESSION["searchType"] = $_GET['type'];
  $type = $_SESSION["searchType"];

  if (isset($_GET['search']) && $_GET['search'] != '') {
    if ($type == 'perfil') {
      $search=$_GET['search'];
      $fachadaBuscar = new fachadaBuscar();
      $searchRes = $fachadaBuscar->Buscardor($search);
      $vistaBuscar = new vistaBuscar();
      $s1 = $vistaBuscar->mostrarListResultP($searchRes["Perfil"]);
      echo $s1;
    }else{
      if ($type == 'grupo') {
        $search=$_GET['search'];
        $fachadaBuscar = new fachadaBuscar();
        $searchRes = $fachadaBuscar->Buscardor($search);
        $vistaBuscar = new vistaBuscar();
        $s1 = $vistaBuscar->mostrarListResultG($searchRes["Grupo"]);
        echo $s1;
      }else{
        if ($type == 'evento') {
          $search=$_GET['search'];
          $fachadaBuscar = new fachadaBuscar();
          $searchRes = $fachadaBuscar->Buscardor($search);
          $vistaBuscar = new vistaBuscar();
          $s1 = $vistaBuscar->mostrarListResultE($searchRes["Evento"]);
          echo $s1;
        }else{
          if ($type == 'noticia') {
            $search=$_GET['search'];
            $fachadaBuscar = new fachadaBuscar();
            $searchRes = $fachadaBuscar->Buscardor($search);
            $vistaBuscar = new vistaBuscar();
            $s1 = $vistaBuscar->mostrarListResultN($searchRes["Noticia"]);
            echo $s1;
          }
        }
      }
    }
  }
}else{
  if (isset($_GET['search']) && $_GET['search'] != '') {

    $search=$_GET['search'];
    $fachadaBuscar = new fachadaBuscar();
    $searchRes = $fachadaBuscar->Buscardor($search);
    $vistaBuscar = new vistaBuscar();
    $s1 = $vistaBuscar->mostrarListResultP($searchRes["Perfil"]);
    $s2 = $vistaBuscar->mostrarListResultG($searchRes["Grupo"]);
    $s3 = $vistaBuscar->mostrarListResultE($searchRes["Evento"]);
    $s4 = $vistaBuscar->mostrarListResultN($searchRes["Noticia"]);
    echo $s1.$s2.$s3.$s4;
  }else{
  
    echo "<p>error con la busqueda </p>";
  }
}
?>